//
//  ComposeViewController.swift
//  MyWeibo
//
//  Created by 余丽丽 on 15/10/26.
//  Copyright © 2015年 余丽丽. All rights reserved.
//

import UIKit

class ComposeViewController: UIViewController {
    
    override func viewDidLoad() {
        view.backgroundColor = UIColor.orangeColor()
        setupNavacationBar()    /* 准备navacationBar */
        view.addSubview(toolBar) /* 准备toolbar       */
        view.addSubview(textView)           /* 准备textView      */
        addPhotoView()          /* 准备photoView     */
        print(view.frame)
        setupUI()               /* layout布局        */
    }
    
    private func setupNavacationBar(){
        //设置导航栏的内容
    navigationItem.leftBarButtonItem = UIBarButtonItem(title: "关闭", style: UIBarButtonItemStyle.Plain, target: self, action: "close")
    navigationItem.rightBarButtonItem = UIBarButtonItem(title: "发送", style: UIBarButtonItemStyle.Plain, target: self, action: "sendWeibo")
        navigationItem.rightBarButtonItem?.enabled = false
        navigationItem.titleView = titleView
       
    }
    
    
    
    ///  点击导航栏[关闭]按钮
    @objc private func close(){
    
    
    }
    
    ///  点击导航栏的[发送]按钮,发送微博
    @objc private func sendWeibo(){
    
    
    }
    
    private func addTextView(){
        
    
    
    }
    
    private func addPhotoView(){
    
    
    }
    

    
    private func setupUI(){
    
    
    
    }
    
    /// 根据图片名返回UIBarButtonItem
    private func BarButton(img:String) -> UIBarButtonItem {
        
        return UIBarButtonItem(customView: UIButton(title: "", imageName: img, highImg: (img + "_highlighted"), target: nil, action: nil))
    }
    
    /// 根据图片名和action名返回UIBarButtonItem
   private func BarButton(img:String,action:String) -> UIBarButtonItem{
        
        return UIBarButtonItem(customView: UIButton(title: "", imageName: img, highImg: (img + "_highlighted"), target: self, action: action))
    }
    
    /// 懒加载导航栏标题View
    private lazy var titleView: UIView = {
    
        let view = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 32))
        let title = UILabel(color: UIColor.blackColor(), fontSize: 16)
        title.text = "发微博"
        title.sizeToFit()
        let user = UILabel(color: UIColor.lightGrayColor(), fontSize: 12)
        user.text = UserAccount.loadAccount()?.name
        user.sizeToFit()
        view.addSubview(title)
        view.addSubview(user)
        
        title.ff_AlignInner(type: ff_AlignType.TopCenter, referView: view, size: nil)
        user.ff_AlignInner(type: ff_AlignType.BottomCenter, referView: view, size: nil)
        user.ff_AlignHorizontal(type: ff_AlignType.BottomCenter, referView: title, size: nil)
     
        return view
    }()
    
    
    /// 懒加载toolBar
    private lazy var toolBar: UIToolbar = {
        
        let tool = UIToolbar()
        tool.backgroundColor = UIColor(white: 0.8, alpha: 1.0)
        tool.frame = CGRect(x: 0.0, y: UIScreen.mainScreen().bounds.height - 44.0, width: UIScreen.mainScreen().bounds.width, height: 44.0)
        
       
        var items = [UIBarButtonItem]()
        
        items.append(self.BarButton("compose_toolbar_picture"))
        items.append(self.BarButton("compose_mentionbutton_background"))
        items.append(self.BarButton("compose_trendbutton_background"))
        items.append(self.BarButton("compose_emoticonbutton_background",action:"inputEmoticon"))
        items.append(self.BarButton("compose_addbutton_background"))


        tool.items = items
        tool.FlexibleTool()
        
        return tool
    }()
    
    private lazy var textView: UITextView = {
        let tv = UITextView()
        //DOTO:|设置textView的一些属性
        tv.font = UIFont.systemFontOfSize(18.0)
        // 允许垂直滑动
        tv.alwaysBounceHorizontal = true
        // 拖拽关闭键盘
        tv.keyboardDismissMode = UIScrollViewKeyboardDismissMode.OnDrag
        tv.frame = CGRect(x: 0, y:64, width: UIScreen.mainScreen().bounds.width, height: UIScreen.mainScreen().bounds.height - 44.0 - 64.0)
        tv.keyboardAppearance = UIKeyboardAppearance.Alert
        tv.editable = true
        tv.backgroundColor = UIColor.cyanColor()
        return tv
    
    }()
    
    
}




